package com.example.pattern.chainOfResponsibility.impl;

import com.example.pattern.chainOfResponsibility.Handler;
import com.example.pattern.chainOfResponsibility.entity.Request;

import java.util.Objects;

public class AuthorityHandler extends Handler {
    public AuthorityHandler(Handler next) {
        super(next);
    }

    @Override
    public boolean process(Request request) {
        if(!request.isAuthority()){
            System.out.println("正在授权，授权成功");
            request.setAuthority(true);
            Handler next = getNext();
            if(Objects.nonNull(next)){
                return next.process(request);
            }else{
                return true;
            }
        }
        return false;
    }
}
